package com.ssy.lingxi.marketing.controller.activity;

import com.ssy.lingxi.common.constant.marketing.ActivityTypeEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.model.constant.PlatformActivityInnerStatusEnum;
import com.ssy.lingxi.marketing.model.constant.PlatformActivityOuterStatusEnum;
import com.ssy.lingxi.marketing.model.vo.activity.request.*;
import com.ssy.lingxi.marketing.model.vo.activity.response.*;
import com.ssy.lingxi.marketing.model.vo.common.request.CommonIdReq;
import com.ssy.lingxi.marketing.model.vo.common.response.PageItemVO;
import com.ssy.lingxi.marketing.model.vo.coupon.request.ActivityPlatformCouponRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.response.ActivityGoodsCouponResponse;
import com.ssy.lingxi.marketing.model.vo.coupon.response.ActivityPrizeCouponResponse;
import com.ssy.lingxi.marketing.service.ICommonService;
import com.ssy.lingxi.marketing.service.IPlatformActivityService;
import com.ssy.lingxi.marketing.service.IPlatformCouponService;
import com.ssy.lingxi.marketing.serviceimpl.base.activity.BaseActivityRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collections;
import java.util.List;

/**
 * @menu 平台后台-平台营销活动管理
 * @author ds
 * @date 2021/6/18
 * @version 2.0.0
 */
@RestController
@RequestMapping("/marketing/platform/activity")
public class PlatformActivityController extends BaseController {

    @Resource
    private IPlatformActivityService platformActivityService;
    @Resource
    private ICommonService commonService;
    @Resource
    private BaseActivityRecordService activityRecordService;
    @Resource
    private IPlatformCouponService platformCouponService;

    /**
     * 平台营销活动查询 - 外部状态列表
     */
    @RequestMapping(value = "/getOuterStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getOuterStatusList() {
        return commonService.getStatusList(PlatformActivityOuterStatusEnum.class);
    }

    /**
     * 平台营销活动查询 - 内部状态列表
     */
    @RequestMapping(value = "/getInnerStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getStatusList() {
        return commonService.getStatusList(PlatformActivityInnerStatusEnum.class);
    }

    /**
     * 平台营销活动查询 - 活动类型列表
     */
    @RequestMapping(value = "/getActivityTypeList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getActivityTypeList() {
        return commonService.getStatusList(ActivityTypeEnum.class);
    }

    /**
     * 平台营销活动查询 - 分页列表
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformActivitySummaryPageResp>> pageSummary(@Valid PlatformActivityPageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageSummary(loginUser, pageReq);
    }

    /**
     * 平台营销活动查询 - 活动详情
     */
    @GetMapping(value = "/detail")
    public Wrapper<PlatformActivityDetailResp> detail(@Valid CommonIdReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.detail(loginUser, req);
    }

    /**
     * 平台营销活动查询 - 活动详情 - 活动商品(分页)
     */
    @RequestMapping(value = "/detail/goods/page", method = RequestMethod.GET)
    public Wrapper<PageData<PfActivitySignUpGoodsPageResp>> pageByActivityGoods(@Valid PfActivityGoodsPageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageByActivityGoods(loginUser, pageReq);
    }

    /**
     * 平台营销活动查询 - 活动详情 - 活动商品 - 选择附属优惠券
     **/
    @RequestMapping(value = "/detail/goods/coupon/select", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityGoodsCouponResponse>> selectSubsidiaryCouponList(ActivityPlatformCouponRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.selectSubsidiaryCouponList(request, loginUser);
    }

    /**
     * 平台营销活动查询 - 活动详情 - 奖品 - 选择0元购买抵扣券
     **/
    @RequestMapping(value = "/detail/prize/coupon/select", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityPrizeCouponResponse>> selectPrizeCouponList(ActivityPlatformCouponRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.selectPrizeCouponList(request, loginUser);
    }

    /**
     * 平台营销活动查询 - 活动详情 - 外部流转记录(分页)
     */
    @RequestMapping(value = "/outer/record/page", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityOuterRecordResp>> pageOuterRecordList(@Valid ActivityOuterRecordPageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return activityRecordService.pagePlatformActivityOuterRecord(loginUser, pageReq);
    }

    /**
     * 平台营销活动查询 - 活动详情 - 内部流转记录(分页)
     */
    @RequestMapping(value = "/inner/record/page", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityInnerRecordResp>> pageInnerRecordList(@Valid ActivityInnerRecordPageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return activityRecordService.pagePlatformActivityInnerRecord(loginUser, pageReq);
    }

    /**
     * 平台营销活动查询 - 取消
     */
    @RequestMapping(value = "/cancel", method = RequestMethod.POST)
    public Wrapper<Void> cancel(@RequestBody @Valid ActivityActionReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.cancel(loginUser, req);
    }

    /**
     * 平台营销活动查询 - 终止
     */
    @RequestMapping(value = "/stop", method = RequestMethod.POST)
    public Wrapper<Void> stop(@RequestBody @Valid ActivityActionReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.stop(loginUser, req);
    }

    /**
     * 平台营销活动查询 - 重新启动
     */
    @RequestMapping(value = "/restart", method = RequestMethod.POST)
    public Wrapper<Void> restart(@RequestBody @Valid ActivityActionReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.restart(loginUser, req);
    }

    /**
     * 平台营销活动查询 - 修改时间
     */
    @RequestMapping(value = "/update/time", method = RequestMethod.POST)
    public Wrapper<Void> updateTime(@RequestBody @Valid PlatformActivityUpdateTimeReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.updateTime(loginUser, req);
    }

    /**
     * 待新增平台营销活动 - 分页列表
     */
    @RequestMapping(value = "/page/tobe/add", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformActivityAddPageResp>> pageByToBeAdd(@Valid PlatformActivityPageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageByToBeAdd(loginUser, pageReq);
    }

    /**
     * 待新增平台营销活动 - 新增
     */
    @PostMapping(value = "/save")
    public Wrapper<Void> save(@RequestBody @Valid PlatformActivityAddReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.savePlatformActivity(loginUser, req);
    }

    /**
     * 待新增平台营销活动 - 修改
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Valid PlatformActivityUpdateReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.updatePlatformActivity(loginUser, req);
    }

    /**
     * 待新增平台营销活动 - 提交
     */
    @PostMapping(value = "/submit")
    public Wrapper<Void> submit(@Valid @RequestBody ActivitySubmitReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.submit(loginUser, req);
    }

    /**
     * 待新增平台营销活动 - 批量提交
     */
    @PostMapping(value = "/submit/batch")
    public Wrapper<Void> batchSubmit(@Valid @RequestBody CommonIdsReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.batchSubmit(loginUser, req);
    }

    /**
     * 待新增平台营销活动 - 删除
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@Valid @RequestBody ActivitySubmitReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.batchDelete(loginUser, Collections.singletonList(req.getId()));
    }

    /**
     * 待新增平台营销活动 - 批量删除
     */
    @PostMapping(value = "/delete/batch")
    public Wrapper<Void> batchDelete(@Valid @RequestBody CommonIdsReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.batchDelete(loginUser, req.getIds());
    }

    /**
     * 待审核报名 - 分页列表
     */
    @RequestMapping(value = "/page/tobe/sign/up", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformActivityTobeSignUpPageResp>> pageByToBeSignUp(@Valid PlatformActivityTobeSignUpReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageByToBeSignUp(loginUser, pageReq);
    }

    /**
     * 待审核报名 - 活动详情
     */
    @GetMapping(value = "/detail/tobe/sign/up")
    public Wrapper<PlatformActivitySignUpDetailResp> detailSignUp(@Valid PlatformActivitySignUpDetailReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.detailSignUp(loginUser, req);
    }

    /**
     * 待审核报名- 活动详情 - 活动商品(分页)
     */
    @RequestMapping(value = "/detail/goods/page/tobe/sign/up", method = RequestMethod.GET)
    public Wrapper<PageData<PfActivitySignUpGoodsPageResp>> pageByActivityGoodsSignUp(@Valid PfActivitySignUpGoodsPageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageByActivityGoodsSignUp(loginUser, pageReq);
    }

    /**
     * 待审核报名 - 审核报名
     */
    @PostMapping(value = "/examine/sign/up")
    public Wrapper<Void> examineSignUp(@RequestBody @Valid PlatformActivityExamineSignUpReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.examineSignUpUpdate(loginUser, req);
    }

    /**
     * 待提交审核平台营销活动 - 分页列表
     */
    @RequestMapping(value = "/page/tobe/submit", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformActivitySubmitPageResp>> pageByToBeSubmit(@Valid PlatformActivityToBeSubmitPageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageByToBeSubmit(loginUser, pageReq);
    }

    /**
     * 待提交审核平台营销活动 - 提交审核
     */
    @PostMapping(value = "/submit/examine")
    public Wrapper<Void> submitExamine(@RequestBody @Valid ActivitySubmitReq dto) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.submitExamine(loginUser, dto);
    }

    /**
     * 待审核平台营销活动(一级) - 分页列表
     */
    @RequestMapping(value = "/page/examine/step1", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformActivityExamResp>> pageByExamineStep1(@Valid PlatformActivityStep1PageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageByExamineStep1(loginUser, pageReq);
    }

    /**
     * 待审核平台营销活动(一级) - 审核
     */
    @PostMapping(value = "/examine/step1")
    public Wrapper<Void> pageByExamineStep1(@RequestBody @Valid ActivityExamineReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.examineStep1Update(loginUser, req);
    }

    /**
     * 待审核平台营销活动(二级) - 分页列表
     */
    @RequestMapping(value = "/page/examine/step2", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformActivityExamResp>> pageByExamineStep2(@Valid PlatformActivityStep1PageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageByExamineStep2(loginUser, pageReq);
    }

    /**
     * 待审核平台营销活动(二级) - 审核
     */
    @PostMapping(value = "/examine/step2")
    public Wrapper<Void> pageByExamineStep2(@RequestBody @Valid ActivityExamineReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.examineStep2Update(loginUser, req);
    }

    /**
     * 待上线平台营销活动 - 分页列表
     */
    @RequestMapping(value = "/page/tobe/online", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformActivityOnlineResp>> pageByToBeOnline(@Valid PlatformActivityStep1PageReq pageReq) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.pageByToBeOnline(loginUser, pageReq);
    }

    /**
     * 待上线平台营销活动 - 上线活动
     */
    @PostMapping(value = "/online")
    public Wrapper<Void> online(@RequestBody @Valid ActivitySubmitReq req) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformActivityService.onlineUpdate(loginUser, req);
    }
}
